home *** CD-ROM | disk | FTP | other *** search
/ Imagine the Universe (9th Edition) / Imagine the Universe 9 - Disc 1.iso / pc / imagine / docs / science / quiz_l1 / js / dwarfs.js < prev    next >
Text File  |  2002-12-30  |  2KB  |  64 lines

  1. // Path needs to be relative link from page that called this script
  2. Image1 = new Image();
  3. Image1.src = "../../../Images/heasarc/icons/blank2.gif";
  4. Image2 = new Image();
  5. Image2.src = "../../../Images/heasarc/icons/star2.gif";
  6.  
  7. total = 3;
  8.  
  9. yourAnswer = new Array(total);
  10. answer = new Array("A","C","A");
  11.  
  12. function Swap(start, end) {
  13.     for (i = start; i <= end; i++) {
  14.         document.images["correct" + i].src = Image2.src;
  15.     }
  16.     return true;
  17. }
  18.  
  19.  
  20. function AssignClick(letter, position) {
  21.     yourAnswer[position] = letter.value;
  22. }
  23.  
  24. function CheckMe() {
  25.  
  26. var count = 0;
  27.  
  28.     for (i = 0; i < total; i++) {
  29.         if (yourAnswer[i] == answer[i]) {count++;}
  30.     }
  31.  
  32.     Swap(1, total);
  33.  
  34.     var win = window.open("", "score_window", "width=300,height=300, resizable=yes,scrollbars=yes");
  35.  
  36.     win.document.write('<HTML>\n<HEAD>\n<TITLE>Your Score</TITLE>\n</HEAD>\n');
  37.     win.document.write('<BODY BGCOLOR="#FFFFFF" TEXT="#000094" LINK="#7D5F00"');            win.document.write(' VLINK="#9E0A42" ALINK="#FF0000">');
  38.     win.document.write('<H2 ALIGN="CENTER">');
  39.  
  40.     if (count == total) {
  41.         win.document.write('<P ALIGN="CENTER">\n');
  42.         win.document.write('<IMG SRC="../../../Images/icons/fireworks.gif" BORDER=0>\n');
  43.         win.document.write('</P>\n');
  44.     }
  45.     win.document.write ("Your score is " + 
  46.         Math.round(count*100/total) + " %!\n</H2>\n</P><P>\n");
  47.  
  48.     win.document.write("<CENTER>")
  49.     win.document.write("<FORM>");
  50.     win.document.write("<TABLE BORDER=5 CELLPADDING=10>");
  51.     win.document.write("<TR><TD ALIGN=\"CENTER\">");
  52.     win.document.write("<INPUT TYPE=button VALUE=\"Close\" onClick=\"window.close()\"></TD></TR>");
  53.     win.document.write("</TABLE>");
  54.     win.document.write("</FORM>");
  55.     win.document.write("</CENTER>");
  56.     if (count < total) {
  57.         win.document.write ("<CENTER>\n</P><P><P><BR><BR><BR>\n");
  58.         win.document.write ("Stars are next to the correct answers.</P><P>\n");
  59.         win.document.write ("</CENTER>\n");
  60.     }
  61.  
  62.     win.document.write('</BODY>\n</HTML>\n');
  63. }
  64.